package com.whnk.model.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.whnk.common.log.annotation.Log;
import com.whnk.common.log.enums.BusinessType;
import com.whnk.common.security.annotation.PreAuthorize;
import com.whnk.model.domain.DefTModelinfo;
import com.whnk.model.service.IDefTModelinfoService;
import com.whnk.common.core.web.controller.BaseController;
import com.whnk.common.core.web.domain.AjaxResult;
import com.whnk.common.core.utils.poi.ExcelUtil;
import com.whnk.common.core.web.page.TableDataInfo;

/**
 * 模型定义Controller
 * 
 * @author whnk
 * @date 2021-08-31
 */
@RestController
@RequestMapping("/modelinfo")
public class DefTModelinfoController extends BaseController
{
    @Autowired
    private IDefTModelinfoService defTModelinfoService;

    /**
     * 查询模型定义列表
     */
    @PreAuthorize(hasPermi = "model:modelinfo:list")
    @GetMapping("/list")
    public TableDataInfo list(DefTModelinfo defTModelinfo)
    {
        startPage();
        List<DefTModelinfo> list = defTModelinfoService.selectDefTModelinfoList(defTModelinfo);
        return getDataTable(list);
    }

    /**
     * 导出模型定义列表
     */
    @PreAuthorize(hasPermi = "model:modelinfo:export")
    @Log(title = "模型定义", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DefTModelinfo defTModelinfo) throws IOException
    {
        List<DefTModelinfo> list = defTModelinfoService.selectDefTModelinfoList(defTModelinfo);
        ExcelUtil<DefTModelinfo> util = new ExcelUtil<DefTModelinfo>(DefTModelinfo.class);
        util.exportExcel(response, list, "模型定义数据");
    }

    /**
     * 获取模型定义详细信息
     */
    @PreAuthorize(hasPermi = "model:modelinfo:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(defTModelinfoService.selectDefTModelinfoById(id));
    }

    /**
     * 新增模型定义
     */
    @PreAuthorize(hasPermi = "model:modelinfo:add")
    @Log(title = "模型定义", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DefTModelinfo defTModelinfo)
    {
        return toAjax(defTModelinfoService.insertDefTModelinfo(defTModelinfo));
    }

    /**
     * 修改模型定义
     */
    @PreAuthorize(hasPermi = "model:modelinfo:edit")
    @Log(title = "模型定义", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DefTModelinfo defTModelinfo)
    {
        return toAjax(defTModelinfoService.updateDefTModelinfo(defTModelinfo));
    }

    /**
     * 删除模型定义
     */
    @PreAuthorize(hasPermi = "model:modelinfo:remove")
    @Log(title = "模型定义", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(defTModelinfoService.deleteDefTModelinfoByIds(ids));
    }
}
